package com.lushuan.ch07_springboot_servlet.cofig;

import com.lushuan.ch07_springboot_servlet.servlet.BeanServlet;
import com.lushuan.ch07_springboot_servlet.servlet.HelloServlet;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 注册Servlet三大组件的方式二
 */
@Configuration
public class MyWebMvcConfigure {

    @Bean
    public ServletRegistrationBean myServlet() {
        // 声明一个servlet注册器bean
        ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean<>();
        // 设置相应的Servlet
        servletRegistrationBean.setServlet(new BeanServlet());
        // 设置名字
        servletRegistrationBean.setName("BeanServlet");
        // 添加映射规则
        servletRegistrationBean.addUrlMappings("/BeanServlet");
        return servletRegistrationBean;
    }


}
